<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../admin.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<xsl:param name="cnt" select="count(response/object[@type='cp_item'])" />
		
		
		<xsl:if test="$cnt = 0">
			<div id="favorite_items" class="items" />
			
			<span class="empty" id="empty_favorite">пусто</span>
		</xsl:if>
		
		<xsl:if test="$cnt != 0">
			<div id="favorite_items" class="items">
				<xsl:apply-templates select="response/object[@type='cp_item']" />
			</div>
			
			<span class="empty" id="empty_favorite" style="display:none">пусто</span>
		</xsl:if>
		
		
		<div id="item_getter" class="getter_disabled" style="display:none">Отпустите ярлык здесь</div>
	</xsl:template>
	
	<xsl:template match="object[@type='cp_item']">
		<xsl:param name="dirId" select="property[@name='link_dir_id']/value" />
		<xsl:param name="itemModule" select="property[@name='link_module']/value" />
		<xsl:param name="itemMethod" select="property[@name='link_method']/value" />
		<xsl:param name="icon" select="property[@name='icon']/value" />
		
		<div class="item" id="favorite_wrapper_{@id}" onmouseover="$('#delete_favorite_{@id}').show()" onmouseout="$('#delete_favorite_{@id}').hide()">
			<div class="delete_favorite" id="delete_favorite_{@id}" style="display:none">
				<img title="Удалить" src="{$baseURI}/images/admin/del-fav.png" onclick="deleteFavorite({@id}, 'favorite_wrapper_{@id}')" />
			</div>
			
			<span class="drag" id="favorite_{@id}">
				<div class="icon">
					<xsl:attribute name="style">
						<xsl:text>background-image: url("</xsl:text>
						<xsl:choose>
							<xsl:when test="$icon != ''">
								<xsl:value-of select="concat($baseURI, $icon)" />
							</xsl:when>
							<xsl:when test="$itemModule != ''">
								<xsl:value-of select="concat($baseURI, '/images/cp/file.png')" />
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="concat($baseURI, '/images/cp/folder.png')" />
							</xsl:otherwise>
						</xsl:choose>
						<xsl:text>");cursor:auto</xsl:text>
					</xsl:attribute>
				</div>
				
				<div class="link">
					<a>
						<xsl:attribute name="href">
							<xsl:choose>
								<xsl:when test="$itemModule != ''">
									<xsl:value-of select="concat($baseURI, '/admin/', $itemModule)" />
									
									<xsl:if test="$itemMethod != ''">
										<xsl:value-of select="concat('/', $itemMethod)" />
									</xsl:if>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat($baseURI, '/admin/cp/dir/', @id)" />
								</xsl:otherwise>						
							</xsl:choose>
						</xsl:attribute>
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</div>
			</span>
		</div>	
	</xsl:template>

</xsl:stylesheet>